<%= render :partial => "apo/navigation" %>

<% cache :action => :list, :action_suffix => "list_#{@filter}_#{@sort_by}_#{session[:user].admin?}" do %>
    <div id="content-pri-frame">

      <div id="content-pri-frame-gener">

    <div style="margin-bottom: 0.5em">
        <% form_tag({:action => "list"}, {:style => "display: inline"}) do %>
            Showing:
            <% unless params[:filter].nil? %>
                <%= select "filter", "type",
                           [
                                   ["Current Members", nil],
                                   ["All", "All"],
                                   ["Actives", "Active"],
                                   ["Pledges", "Pledge"],
                                   ["New Actives", "New Active"],
                                   ["Associates", "Associate"],
                                   ["Probates", "Probate"],
                                   ["Neophytes", "Neophyte"],
                                   ["Away From School", "Away From School"],
                                   ["Alums", "Alum"],
                                   ["Advisors", "Advisor"]
                           ],
                           {:selected => params[:filter][:type]},
                           {:onchange => 'this.form.submit();'} %>
            <% else %>
                <%= select "filter", "type",
                           [
                                   ["Current Members", nil],
                                   ["All", "All"],
                                   ["Actives", "Active"],
                                   ["Pledges", "Pledge"],
                                   ["New Actives", "New Active"],
                                   ["Associates", "Associate"],
                                   ["Probates", "Probate"],
                                   ["Neophytes", "Neophyte"],
                                   ["Away From School", "Away From School"],
                                   ["Alums", "Alum"],
                                   ["Advisors", "Advisor"]
                           ],
                           {},
                           {:onchange => 'this.form.submit();'} %>
            <% end %>
        <% end %>
        <% if session[:user].admin? %>
            <% form_tag({:action => "create", :id => params[:id]}, {:style => "display: inline"}) do %>
                <%= submit_tag "Create New Member" %>
            <% end %>
        <% end %>
    </div>

    <div class="container memberContainer">

    <div class="cellRow cellRowHeader">
        <div class="cellBlock">
            #
        </div>
        <div class="cellBlock">
            <%= link_to "Name", :action => "list", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Service Points", :action => "list", :sort_by => "stored_service_hours", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Leadership Points", :action => "list", :sort_by => "stored_leaderships", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Fellowship Points", :action => "list", :sort_by => "stored_fellowships", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Meeting Points", :action => "list", :sort_by => "stored_active_meetings", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Fundraising Points", :action => "list", :sort_by => "stored_fundraisers", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Dues", :action => "list", :sort_by => "stored_dues", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Tri-Sectionals", :action => "list", :sort_by => "stored_trisecs", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "Pledge Reqs", :action => "list", :sort_by => "stored_pledge_reqs", :filter => {:type => @filter} %>
        </div>
        <div class="cellBlock">
            <%= link_to "%", :action => "list", :sort_by => "stored_percent_done", :filter => {:type => @filter} %>
        </div>
        <% if session[:user].admin? %>
            <div class="cellBlock">
                &nbsp;
            </div>
        <% end %>
    </div>

    <% x = 1 %>
    <% service_hours = 0 %>

    <% Member.find_members(@filter, @sort_by).each do |member| %>
        <% memberData = Member.getData(member, Event.getCurrentSemester) %>
        <div class="cellRow cellRow<%= (x%2==0) ? 1 : 2 %> highlightRow">

            <% if member.status == "Active" or member.status == "New Active" or member.status == "Associate" or member.status == "Probate" or member.status == "Neophyte" %>
                <div class="cellBlock" style="text-align: right;">
                    <%= x %>
                </div>
                <div class="cellBlock" style="text-align: left;">
                    <%= link_to h(member.last_first), :action => "show", :id => member %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["service"]["actual"] %>/<%= memberData["total_required_hours"] %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["leadership"]["actual"].to_i %>/<%= Member.active_leaderships_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["fellowship"]["actual"].to_i %>/<%= Member.active_fellowships_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["meeting"]["actual"].to_i %>/<%= Member.active_meetings_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["fundraiser"]["actual"].to_i %>/<%= Member.active_fundraisers_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["dues"].to_i %>/<%= Member.active_dues_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["trisec"]["actual"].to_i %>/<%= Member.active_trisecs_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["percent"].to_i %>
                </div>
                <% if session[:user].admin? %>
                    <div class="cellBlock">
                        <%= link_to "x", :action => "remove", :id => member %>
                    </div>
                <% end %>
            <% elsif member.status == "Pledge" %>
                <div class="cellBlock" style="text-align: right;">
                    <%= x %>
                </div>
                <div class="cellBlock" style="text-align: left;">
                    <%= link_to h(member.last_first), :action => "show", :id => member %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["service"]["actual"] %>/<%= memberData["total_required_hours"] %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["leadership"]["actual"].to_i %>/<%= Member.pledge_leaderships_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["fellowship"]["actual"].to_i %>/<%= Member.pledge_fellowships_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["meeting"]["actual"].to_i %>/<%= Member.pledge_meetings_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["fundraiser"]["actual"].to_i %>/<%= Member.pledge_fundraisers_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["dues"].to_i %>/<%= Member.pledge_dues_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["pledge_req"]["actual"].to_i %>/<%= Member.pledge_reqs_requirement %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    <%= h memberData["percent"].to_i %>
                </div>
                <% if session[:user].admin? %>
                    <div class="cellBlock">
                        <%= link_to "x", :action => "remove", :id => member %>
                    </div>
                <% end %>

            <% else %>
                <div class="cellBlock" style="text-align: right;">
                    <%= x %>
                </div>
                <div class="cellBlock" style="text-align: left;">
                    <%= link_to h(member.last_first), :action => "show", :id => member %>
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <div class="cellBlock" style="text-align: center;">
                    &nbsp;
                </div>
                <% if session[:user].admin? %>
                    <div class="cellBlock">
                        <%= link_to "x", :action => "remove", :id => member %>
                    </div>
                <% end %>
            <% end %>
        </div>

        <% if x%25 == 0 %>
            <div class="cellRow cellRowHeader">
                <div class="cellBlock">
                    #
                </div>
                <div class="cellBlock">
                    <%= link_to "Name", :action => "list", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Service Points", :action => "list", :sort_by => "stored_service_hours", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Leadership Points", :action => "list", :sort_by => "stored_leaderships", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Fellowship Points", :action => "list", :sort_by => "stored_fellowships", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Meeting Points", :action => "list", :sort_by => "stored_active_meetings", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Fundraising Points", :action => "list", :sort_by => "stored_fundraisers", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Dues", :action => "list", :sort_by => "stored_dues", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Tri-Sectionals", :action => "list", :sort_by => "stored_trisecs", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "Pledge Reqs", :action => "list", :sort_by => "stored_pledge_reqs", :filter => {:type => @filter} %>
                </div>
                <div class="cellBlock">
                    <%= link_to "%", :action => "list", :sort_by => "stored_percent_done", :filter => {:type => @filter} %>
                </div>
                <% if session[:user].admin? %>
                    <div class="cellBlock">
                        &nbsp;
                    </div>
                <% end %>
            </div>
        <% end %>

        <% member.up_to_date = true %>
        <% member.save %>

        <% x = x + 1 %>

        <% service_hours = service_hours + member.stored_service_hours %>

    <% end %>

    <div class="cellRow cellRowHeader">

        <div class="cellBlock">

        </div>
        <div class="cellBlock">
            Totals
        </div>
        <div class="cellBlock">
            <%= service_hours %>
        </div>

    </div>

    </div>
<% end %>
<% cache :action => :list, :action_suffix => "emails_#{@filter}" do %>
    <div id="eventBottomDiv" style="text-align: left;">
        <h3><%= h params[:filter].nil? ? "" : params[:filter][:type] %> Email List:</h3>
        <% Member.find_members(@filter, @sort_by).each do |member| %>
            <%= member.email %>,
        <% end %>
      </div>

    </div>
<% end %> 
<%= render :partial => "apo/footer" %>